﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Microsoft.Security.Application;

namespace Billing
{
    public partial class Default : Page
    {
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            string s = ClsPasswordHelper.Encrypt("kit");
            this.DoLogin();
        }

        private void DoLogin()
        {
            ClsUserProfile cls = new ClsUserProfile
            {
                LoginPassword = ClsPasswordHelper.Encrypt(txtPassword.Text),
                LoginId = txtUserName.Text
            };
            DataTable dt = cls.DoLogin();
            if ((dt != null) && (dt.Rows.Count > 0))
            {
                LoginUser.MyUserProfile = cls;
                LoginUser.UserInfomation = dt.Rows[0];
                LoginUser.LoginID = dt.Rows[0]["loginid"].ToString();
                LoginUser.UserID = (long)dt.Rows[0]["UserID"];
                LoginUser.DisplayName = dt.Rows[0]["Name0"].ToString();
                LoginUser.BUID = (long)dt.Rows[0]["BUID"];
                LoginUser.AgencyID = (long)dt.Rows[0]["AgencyID"];
                LoginUser.CostCentreID = (long)dt.Rows[0]["CostCentreID"];
                LoginUser.GroupName = dt.Rows[0]["GroupName"].ToString();
                LoginUser.GroupID = (long)dt.Rows[0]["UserTypeID"];
                LoginUser.Email = dt.Rows[0]["Email"].ToString();
                LoginUser.CurrentLoginDateTime = DateTime.Now.ToString("dd/MM/yyyy HH:mm");
                LoginUser.TreeMenu = new ClsResourceMenu().SelectByStructureWithGroupMemberID(Convert.ToInt64(dt.Rows[0]["UserTypeID"]));
                base.Response.Redirect("DownloadBillReport.aspx", true);
            }
            ucHighlight1.ErrorMessage = Encoder.HtmlEncode("Invalid Login Name or password");
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            ucHighlight1.CloseAll();

        }

    }
}